-
Notifications
You must be signed in to change notification settings - Fork 148
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests for scansourcefiles actor #1190
Conversation
Thank you for contributing to the Leapp project!Please note that every PR needs to comply with the Leapp Guidelines and must pass all tests in order to be mergeable.
Packit will automatically schedule regression tests for this PR's build and latest upstream leapp build. If you need a different version of leapp, e.g. from PR#42, use It is possible to schedule specific on-demand tests as well. Currently 2 test sets are supported,
See other labels for particular jobs defined in the Please open ticket in case you experience technical problem with the CI. (RH internal only) Note: In case there are problems with tests not being triggered automatically on new PR/commit or pending for a long time, please contact leapp-infra. |
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is a common practice to first test the lower level functions as units and then mock them when testing functions that call them.
So in all of these 3 tests, you would just test the functionality on scansourcefiles.scan_file()
. Then you would add a test that tests scansourcefiles.process()
and mock scan_file()
in it, because that function is already covered.
This would reduce the amount of mocks in the lower level tests and also allow you to run the test once per possible input (in this case a file). Then you could use @pytest.mark.parametrize()
to run the test for multiple inputs (files). You can also specify the expected results there to avoid having specific asserts for each one of them.
You can take a look at https://github.com/oamg/leapp-repository/blob/master/repos/system_upgrade/el8toel9/actors/rocescanner/tests/unit_test_rocescanner.py for an example of such tests. First get_roce_nics_lines
is properly tested and then it's mocked when testing process
.
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's now looking a lot better. However some additional changes are requested.
I am sorry, I added 2 comments outside the review by accident.
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
repos/system_upgrade/common/actors/scansourcefiles/tests/unit_test_scansourcefiles.py
Outdated
Show resolved
Hide resolved
f0527fc
to
f32fdca
Compare
My notes:
I will squash commits, and write proper commit message after approved, or when it is finalized. |
/packit build |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that's much better! lgtm!
/packit rebuild-failed |
/packit rebuild-failed |
/packit build |
d207f7d
to
697452a
Compare
When splitting |
Jira: OAMG-10367
697452a
to
7da7cc7
Compare
@fernflower seems that automatic building is broken by general. |
/packit build |
Jira: OAMG-10367 (cherry picked from commit 3066cad)
Jira: OAMG-10367 (cherry picked from commit 3066cad)
Test if files are correctly tracked by actor. Create mocked existent/non-existent, modified/non-modified, rpm owned/not-owned files. Also test non-existent version files.
Jira: OAMG-10367